package com.example.a7822.myapplication.shopcart;


import com.example.a7822.myapplication.base.SPManager;
import com.example.a7822.myapplication.shopcart.beans.ShopBean;
import com.example.a7822.myapplication.utils.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 商店管理
 */
public class SPShopManager extends SPManager {
    private Logger logger = Logger.getLogger(SPShopManager.class);

    // 单例
    private static SPShopManager inst = new SPShopManager();

    public static SPShopManager instance() {
        return inst;
    }

    // 自身状态字段
//    private boolean userDataReady = false;
    private Map<Integer, ShopBean> shopMap = new ConcurrentHashMap<>();
    //modify

    public static ShopBean curShop = new ShopBean();
     public static boolean isUpdate = false;
    public static Map signMap = new HashMap();



    public String getShopAvatar(String shopID) {

        return "";
    }

    @Override
    public void doOnStart() {
    }



    /**
     * 加载本地DB的状态
     * 不管是离线还是在线登陆，loadFromDb 要运行的
     */
    public void onLocalLoginOk() {
       /* logger.d("contact#loadAllUserInfo");

        List<DepartmentEntity> deptlist = dbInterface.loadAllDept();
        logger.d("contact#loadAllDept dbsuccess");

        List<UserEntity> userlist = dbInterface.loadAllUsers();
        logger.d("contact#loadAllUserInfo dbsuccess");

        for (UserEntity userInfo : userlist) {
            // todo DB的状态不包含拼音的，这个样每次都要加载啊
            PinYin.getPinYin(userInfo.getMainName(), userInfo.getPinyinElement());
            shopMap.put(userInfo.getPeerId(), userInfo);
        }

        for (DepartmentEntity deptInfo : deptlist) {
            PinYin.getPinYin(deptInfo.getDepartName(), deptInfo.getPinyinElement());
            departmentMap.put(deptInfo.getDepartId(), deptInfo);
        }
        triggerEvent(UserInfoEvent.USER_INFO_OK);*/
    }

    /**
     * 网络链接成功，登陆之后请求
     */
    public void onLocalNetOk() {
        // 部门信息
        /*int deptUpdateTime = dbInterface.getDeptLastTime();
        reqGetDepartment(deptUpdateTime);

        // 用户信息
        int updateTime = dbInterface.getUserInfoLastTime();
        logger.d("contact#loadAllUserInfo req-updateTime:%d", updateTime);
        reqGetAllUsers();
        //未读好友请求
        onReqLoginUser();
        reqUnreadFriendReq();*/
    }


    @Override
    public void reset() {
//        userDataReady = false;
        shopMap.clear();
    }







    public ShopBean findShop(int shopID) {
        if (shopID > 0 && shopMap.containsKey(shopID)) {
            return shopMap.get(shopID);
        }
        return null;
    }

    /**
     * 请求用户详细信息
     *
     * @param userIds
     */
    public void reqGetDetaillUsers(ArrayList<Integer> userIds) {
        /*logger.i("contact#contact#reqGetDetaillUsers");
        if (null == userIds || userIds.size() <= 0) {
            logger.i("contact#contact#reqGetDetaillUsers return,cause by null or empty");
            return;
        }
        int loginId = IMLoginManager.instance().getLoginId();
        IMBuddy.IMUsersInfoReq imUsersInfoReq = IMBuddy.IMUsersInfoReq.newBuilder()
                .setUserId(loginId)
                .addAllUserIdList(userIds)
                .build();

        int sid = IMBaseDefine.ServiceID.SID_BUDDY_LIST_VALUE;
        int cid = IMBaseDefine.BuddyListCmdID.CID_BUDDY_LIST_USER_INFO_REQUEST_VALUE;
        imSocketManager.sendRequest(imUsersInfoReq, sid, cid, reqGetDetaillUsersLister);*/
    }










    /**------------------------部门相关的协议 end------------------------------*/

    /**
     * -----------------------实体 get set 定义-----------------------------------
     */

    public Map<Integer, ShopBean> getShopMap() {
        return shopMap;
    }




}